//################################
// 版权所有：中国农业银行软件开发中心
// 系统名称：移动办公应用-手机版
// 文件名称：navigatorLevel1.js
// 创建时间：2016年10月21日
// 创建人员：邱原
// 功能说明：根navigator下的1级navigator容器
//################################

'use strict';

import React, { Component } from 'react';
import {
    StyleSheet,
    Navigator,
    BackAndroid,
    AppState,
    View,
    StatusBar,
    Platform,
} from 'react-native';

import PubSub from 'pubsub-js';
import Orientation from 'react-native-orientation';

import {
    Routes,
    PubSubTopics,
    CommonData,
} from '../../common';

import MainContainer from '../../main/containers/mainContainer';
// import EmailNavigator from '../../mail/pages/emailNavigator';
// import ZhsoiNavigator from '../../soi/zhsoi/pages/zhsoiNavigator';
// import ZxsoiNavigator from '../../soi/zxsoi/pages/zxsoiNavigator';
// import CoopNavigator from '../../cooperation/pages/coopNavigator';
// import DataWindowNavigator from '../../datawindows/pages/dataWindowNavigator';
// import FhsoiNavigator from '../../fhsoi/pages/fhsoiNavigator';

var _navigator, _route;

class NavigatorLevel1 extends Component {
    constructor(props) {
        super(props);

        this.renderScene = this.renderScene.bind(this);
        this.configureScene = this.configureScene.bind(this);
        this.onDidFocus = this.onDidFocus.bind(this);

        this.routes = [
            {name: Routes.MAIN, component: MainContainer, data: props.route.data}
        ];

        // BackAndroid.addEventListener('hardwareBackPress', this.goBack);
    }

    componentDidMount() {
        
    }

    componentWillUnmount() {
        
    }
    
    onDidFocus(route) {
        CommonData.isAppInitAfterLogin=false;
        CommonData.currentNavigator=this.navigatorLevel1?this.navigatorLevel1:null;
        CommonData.currentRoute = route;
        var routeName = route.name;
        
        switch (routeName) {
            case Routes.MAIN:
                PubSub.publish(PubSubTopics.MAIN_ONDIDFOCUS);
                break;
            
            default:
                break;
        }
    }

    configureScene(route, routeStack) {
        if (route.friend) {
            return Navigator.SceneConfigs.HorizontalSwipeJump;
        } else {
            return Navigator.SceneConfigs.FadeAndroid;
        }
    }

    renderScene(route, navigator) {
        let Component = route.component;
        _navigator = navigator;
        _route = route;
        
        return (
            <Component navigatorRoot={this.props.navigatorRoot} navigatorLevel1={navigator} route={route} />
        );
    }

    render() {
        return (
            <View style={{flex: 1}}>
                
                <Navigator
                    ref={(ref) => {this.navigatorLevel1 = ref}}
                    style={styles.navigator}
                    configureScene={this.configureScene}
                    renderScene={this.renderScene}
                    initialRoute={this.routes[0]}
                    initialRouteStack={this.routes}
                    onDidFocus={this.onDidFocus}
                />
            </View>
        );
    }
}

const styles = StyleSheet.create({
    navigator: {
        flex: 1,
    },
});

export default NavigatorLevel1;